package projectxxx;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*;
import java.text.SimpleDateFormat;
import com.toedter.calendar.*;

public class OtherSouthStockPanel extends JPanel implements ActionListener
{
	private JPanel otherP=null;
	private JButton addB=null, returnB=null;
	
	MainWestStockPanel mwsp=null;
	
	public OtherSouthStockPanel() 
	{
		otherP = new JPanel(); 
		BoxLayout b5 = new BoxLayout(otherP, BoxLayout.X_AXIS);
		otherP.setLayout(b5);
		addB = new JButton(" Add ");
		addB.setToolTipText(" Add new stock item ");
		addB.addActionListener(this);
		returnB = new JButton(" Return "); 
		returnB.setToolTipText(" Return to main page ");
		returnB.addActionListener(this);
		otherP.add(addB);
		otherP.add(returnB);
		otherP.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
		//setup "this" Jpanel
		this.setLayout(new GridLayout(1,1));
		this.add(otherP);
	}//end of OtherSouthStockPanel constructor

		public void actionPerformed(ActionEvent ae)
	{
		Object source = ae.getSource();
		if(source == addB)
		{
			try
			{
				
				mwsp = new MainWestStockPanel();
				Date date = mwsp.getReleaseDate();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				String bdate = sdf.format(date);
				Date date2 = mwsp.getRentedDate();
				String jdate = sdf.format(date2);
				StockManager sm = new StockManager();
							
				String [] attr = new String [15];
				attr[0] = sm.generateStockId();
				attr[1] = (String )mwsp.mediaTypeJcb.getSelectedItem();
				attr[2] = mwsp.titleTxt.getText();
				attr[3] = (String)mwsp.statusJcb.getSelectedItem();
				attr[4] = mwsp.barcodeTxt.getText();
				attr[5] = mwsp.serialNoTxt.getText();
				attr[6] = mwsp.descriptionTxt.getText();
				attr[7] = (String)mwsp.catNameJcb.getSelectedItem();
				attr[8] = mwsp.runTimeTxt.getText();
				attr[9] = bdate;
				attr[10] = (String)mwsp.genreJcb.getSelectedItem();
				attr[11] = mwsp.ageRestTxt.getText();
				attr[12] = mwsp.directorTxt.getText();
				attr[13] = mwsp.actor1Txt.getText();
				attr[14] = mwsp.actor2Txt.getText();
				attr[15] = jdate;
							
				for(int i = 0; i < attr.length; i++)
				{
					System.out.println(attr[i]);
				}
				
				
				Stock stock = new Stock(attr);
				sm.commitStock(stock);
			}
			catch(Exception excep)
			{
				excep.printStackTrace();
			}	
		}
		if(source == returnB)
		{
			try
			{
				
			}
			catch(Exception excep)
			{
				excep.printStackTrace();
			}
		}
		
	}		
}//end of OtherSouthStockPanel class
